using System.Collections.Generic;

namespace AutoChess
{
    /*
     * 抽象隔离的好处是代码更加可观、可控、易拓展.代价就是调用需要再多封装一程，同时体量变大
     */  
    class ActorAnimator:ActorCmpt
    {
        private float m_moveAnimScale = 1.0f;
        private AnimatorInterface m_interface = null;
        
        private Dictionary<int,bool> m_dicBoolParam = new Dictionary<int, bool>();
        private Dictionary<int,int> m_dictIntParam = new Dictionary<int, int>();
        
        #region 动画速度

        public float GetMoveAnimSpeed()
        {
            return m_moveAnimScale;
        }

        public void SetAnimCtrSpeed(float speed)
        {
            if (m_interface != null)
            {
                m_interface.SetAnimCtrSpeed(speed);
            }
        }
        
        #endregion

        #region 动画触发

        public void SetIntParam(int paramId, int val)
        {
            int existVal;
            if (m_dictIntParam.TryGetValue(paramId, out existVal) && existVal == val)
            {
                return;
            }

            m_dictIntParam[paramId] = val;
            if (m_interface != null)
            {
                m_interface.SetIntParam(paramId,val);
            }
        }

        #endregion
        
        #region 通用接口

        public void PlayAnimator(string aniName)
        {
            if (m_interface != null)
            {
                m_interface.PlayAnimator(aniName);
            }
        }

        public void PlayCrossFade(string aniName, float transitionDuration, int layer, float normalizedTime)
        {
            if (m_interface != null)
            {
                m_interface.PlayCrossFade(aniName,transitionDuration,layer,normalizedTime);
            }
        }
        
        #endregion

        #region 管理接口

        public void BindAnimtorInterface(AnimatorInterface animterface)
        {
            if (m_interface != animterface)
            {
                m_interface = animterface;
                if (animterface != null)
                {
                    if (!animterface.Create((this)))
                    {
                        BLogger.EditorFatal("create animator interface failed: {0}",OwnActor.GetGameObjectName());
                        m_interface = null;
                    }
                }

                //重新应用动画状态
                ApplyAllParam();
            }
        }

        void ApplyAllParam()
        {
            if (m_interface == null)
            {
                return;
            }
            //TODO
        }

        #endregion
    }
}